//封装axios用于发送请求
import axios from "axios";
import store from "@/store";
//创建一个axios实例  http://weldon.net.cn:8889/api/private/v1
const request = axios.create({
  baseURL: "https://lianghj.top:8888/api/private/v1/",
  timeout: 5000,
});

//请求拦截器
request.interceptors.request.use(
  (config) => {
    const { token } = store.state.user;
    // console.log(token);
    if (token) {
      config.headers.Authorization = `${token}`;
    }
    return config;
  },
  (error) => {
    return Promise.reject(error);
  }
);

//响应拦截器
request.interceptors.response.use(
  (response) => {
    //对响应数据做点什么
    return response.data;
  },
  (error) => {
    //对错误做点什么
    return Promise.reject(error);
  }
);
export default request;
